const xml2js = require('xml2js');
const fs = require('fs');

var xmlParser = xml2js.Parser();
var xmlBdr = new xml2js.Builder();

var readXml = fs.createReadStream('city.xml');
var data = '';

readXml.on('data', function(rs){
    data += rs;
    xmlParser.parseString(data, function(err, result){
        if (err) throw err;
        var res = JSON.stringify(result);
        var xml = xmlBdr.buildObject(result);
        var writeXml = fs.createWriteStream('city.json');
        writeXml.write(res);
        writeXml.end();

        var writer = fs.createWriteStream('cityCopy.xml');
        writer.write(xml);
        writer.end();
    });
});